<template>
	<scroll-view scroll-y class="content">
		<!-- 描述：滑动后出现的头部 -->
		<!-- <header-fiexd :opacity="opacity" :nieName="neiName"></header-fiexd> -->
		<view class="header-bg">
			<!-- <view class="status-contents"></view> -->
			<!-- 描述：头部 -->
			<!-- <header-ws :neiName="neiName"></header-ws> -->
			<!-- 描述：功能模块 -->
			<module-list></module-list>
			<!-- 描述：通知公告 -->
			<annunciate :list="noticeList"></annunciate>
		</view>
		<!-- 描述: 轮播图 -->
		<home-swiper :list="noticeList"></home-swiper>
		<!-- 描述：分割线 -->
		<view class="cut-off-rule"></view>
		<!-- 描述：友林社区 -->
		<view class="community-content">
			<view class="community-title">友邻社区</view>
			<!-- 描述：小区活动 -->
			<more-title title="小区活动" type="activity"></more-title>
			<view v-for="item in activityList" :key="item.actID">
				<activity-item :data="item"></activity-item>
			</view>
			<!-- 描述：二手之家 -->
			<more-title title="二手之家" type="goods"></more-title>
			<view v-for="item in usedCommodityList" :key="item.usecID">
				<goods-itme :data="item"></goods-itme>
			</view>
			<!-- 描述：业主分享 -->
			<more-title title="业主分享" type="share"></more-title>
			<view v-for="item in dynamicsList" :key="item.dynID">
				<share-item :data="item"></share-item>
			</view>
		</view>
		<view class="bottom-bow"></view>
	</scroll-view>
</template>

<script>
	import { HomeModel } from '../home.js'
	import util from '../../../common/js/util.js'
	import moreTitle from '../../../components/more-title.vue'
	import homeSwiper from '../../../components/home/index/swiper.vue'
	import headerWs from '../../../components/home/index/header-ws.vue'
	import goodsItme from '../../../components/community/goods-item.vue'
	import shareItem from '../../../components/community/share-item.vue'
	import moduleList from '../../../components/home/index/ModuleList.vue'
	import annunciate from '../../../components/home/index/annunciate.vue'
	import headerFiexd from '../../../components/home/index/header-fiexd.vue'
	import activityItem from '../../../components/community/activity-item.vue'
	const Home = new HomeModel()
	export default {
		components: {
			moduleList,
			annunciate,
			homeSwiper,
			moreTitle,
			activityItem,
			goodsItme,
			shareItem,
			headerFiexd,
			headerWs
		},
		data() {
			return {
				opacity: 0,
				neiName: '',
				noticeList: [], // 通告
				activityList: [], // 活动
				usedCommodityList: [], // 二手
				dynamicsList: [], //朋友圈
				onTop: true
			}
		},
		onLoad() { //页面加载
			Home.isUser() // 调用是否注册方法
				.then(() => {
					return Home.getHomeData() // 调用首页数据方法
				})
				.then(data => {
					this.dataAssignment(data) // 页面赋值
					if (data.isPerInf == 0)  this.selfImprovement() // 提醒用户完善个人信息
				})
				.catch((url) => {
					uni.redirectTo({ url: url })  // 失败 | 则根据url进入注册 或审核页面
				})
		},
		
		onHide() { // 页面隐藏后自动回滚至顶部
			uni.pageScrollTo({ scrollTop: 0 })
		},
		
		onPullDownRefresh() { // 下拉刷新数据
			Home.getHomeData()
				.then(data => {
					this.dataAssignment(data)
					uni.stopPullDownRefresh();
				})
		},
		
		
		onNavigationBarButtonTap() {
			console.log('点击了按钮')
		},
		methods: {
			dataAssignment(data) {
				let tempArray = ['neiName', 'noticeList', 'activityList', 'usedCommodityList', 'dynamicsList']
				tempArray.forEach((item, index) => {
					this[item] = data[item]
				})
				uni.setNavigationBarTitle({
					title: this.neiName
				})
			},
			selfImprovement() { // 完善资料方法
				uni.showModal({
					showCancel: false,
					content: '您当前的用户信息尚未完善，请前去完善',
					success: () => console.log('确定')
				})
			}
		} 
	}
</script>

<style lang="scss">
	@import '../../../common/scss/_common.scss';
	@import '../../../common/css/icon.css';

	.status-contents {
		height: var(--status-bar-height);
	}
	page{
		height: 100%;
	}
	.content {

		.header-bg {
			padding-top: 15upx;
			position: relative;

			&::after {
				content: '';
				position: absolute;
				width: 100%;
				height: 125upx; 
				top: 0;
				bottom: 0;
				left: 0;
				right: 0;
				z-index: -1;
				background-image: linear-gradient(#4FA7E6 ,lighten(#4FA7E6, 10%));
			}
		}
		.cut-off-rule {
			height: 30upx;
			background-color: #F7F7F7;
		}

		.community-content {
			margin-top: ws(15);
			padding: 0 ws(15);

			.community-title {
				font-size: ws(12);
				padding: 0 ws(6);
				border-radius: ws(30);
				display: inline-block;
				color: #fff;
				background-color: $main-color;
			}
		}
	}
</style>
